<template>
  <div class="app-container ">
    <el-form ref="form" size="mini" :model="form" :rules="rules" label-width="180px">
      <el-tabs v-model="activeName">
        <el-tab-pane style="padding-top:10px" label="基本信息" name="基本信息">
          <el-row>
            <el-col :span="24">
              <el-form-item label="系统名称">
                <el-input v-model="form.sys_title" auto-complete="off" clearable placeholder="请输入系统名称" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="logo" prop="logo">
                <ImagesUpload size="mini" file-type="image" :image.sync="form.logo" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="热搜关键词" prop="keyword">
                <Tag :tag-list.sync="form.keyword" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="邮箱">
                <el-input v-model="form.EMAIL" auto-complete="off" clearable placeholder="邮箱" />
              </el-form-item>
            </el-col>
          </el-row>
          <!--<el-row>
            <el-col :span="24">
              <el-form-item label="首页弹窗客服二维码">
                <ImagesUpload size="mini" file-type="image" :image.sync="form.kefuqrcode" />
                <div class="help-block">图片尺寸：600x970像素</div>
              </el-form-item>
            </el-col>
          </el-row>-->
          <el-row>
            <el-col :span="24">
              <el-form-item label="线下订单默认状态">
                <el-radio-group v-model="form.external_order_pay">
                  <el-radio label="0">未付款</el-radio>
                  <el-radio label="1">已付款</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="默认订单自动结算时间" prop="automaticsettlement">
                <el-input-number
                  v-model="form.automaticsettlement"
                  controls-position="right"
                  style="width:300px;"
                  auto-complete="off"
                  clearable
                  :min="0"
                  placeholder="默认订单自动结算时间"
                />
                <div class="help-block">多少天</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="显示商家的默认距离" prop="storedistance">
                <el-input-number
                  v-model="form.storedistance"
                  controls-position="right"
                  style="width:300px;"
                  auto-complete="off"
                  clearable
                  :min="0"
                  placeholder="请输入显示商家的默认距离"
                />
                <div class="help-block">单位：km</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="sysversion=='v3'">
            <el-col :span="24">
              <el-form-item :label="'显示'+lang.technical+'列表的默认距离'" prop="technicaldistance">
                <el-input-number
                  v-model="form.technicaldistance"
                  controls-position="right"
                  style="width:300px;"
                  auto-complete="off"
                  clearable
                  :min="0"
                  :placeholder="'请输入显示'+lang.technical+'列表的默认距离'"
                />
                <div class="help-block">单位：km</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="定位范围">
                <el-radio-group v-model="form.locationscope">
                  <el-radio label="1">省</el-radio>
                  <el-radio label="2">市</el-radio>
                  <el-radio label="3">区/县</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="平台显示商家服务/商品">
                <el-radio-group v-model="form.show_storegoods">
                  <el-radio label="0">不显示</el-radio>
                  <el-radio label="1">显示</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="首页订单播报">
                <el-radio-group v-model="form.is_broadcast">
                  <el-radio label="0">关闭</el-radio>
                  <el-radio label="1">开启</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="小程序首页定位">
                <el-radio-group v-model="form.is_close_getposition">
                  <el-radio label="1">关闭</el-radio>
                  <el-radio label="0">开启</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="购买商品送积分">
                <el-radio-group v-model="form.is_close_points">
                  <el-radio label="1">关闭</el-radio>
                  <el-radio label="0">开启</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="定时处理连接">
                {{ form.autoapi }}
                <div class="help-block">时间：一般5分钟</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="版权信息" prop="copyright">
                <el-input v-model="form.copyright" auto-complete="off" clearable placeholder="请输入版权信息" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="系统状态">
                <el-radio-group v-model="form.sys_status">
                  <el-radio label="0">关闭</el-radio>
                  <el-radio label="1">开启</el-radio>
                </el-radio-group>
                <div class="help-block">关闭后，用户打不开，后台还可以使用</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="小程序审核">
                <el-radio-group v-model="form.examine_status">
                  <el-radio label="0">关闭</el-radio>
                  <el-radio label="1">开启</el-radio>
                </el-radio-group>
                <div class="help-block">小程序审核过程中打开</div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
      <el-form-item>
        <el-button size="mini" type="primary" @click="submit">保存设置</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>
<script>
import ImagesUpload from '@/components/common/ImagesUpload.vue'
import Tag from '@/components/common/Tag.vue'
export default {
  name: 'Configindex',
  components: {
    ImagesUpload,
    Tag
  },
  data() {
    return {
      lang: {},
      form: {},
      select: {},
      sysversion: '',
      loading: false,
      activeName: '基本信息',
      rules: {}
    }
  },
  mounted() {
    this.$api.post('/Lang/getlang').then(res => {
      this.lang = res.data
    })
    this.$api.post('/config/getField').then(res => {
      this.select = res.data
    })
    this.$api.get('/Sysbase/sysversion', this.form).then(res => {
      this.sysversion = res.data
    })
    this.$api.post('/config/getInfo').then(res => {
      this.form = JSON.stringify(res.data) == '[]' ? {} : res.data
      this.setDefaultVal('keyword')
    })
  },
  methods: {
    submit() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          this.$api.post('/config/update', this.form).then(res => {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
          }).catch(() => {
            this.loading = false
          })
        }
      })
    },
    setDefaultVal(key) {
      if (this.form[key] == null || this.form[key] == '') {
        this.form[key] = []
      }
    }
  }
}
</script>
